package com.ksd.modules.special.controller;

import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.special.po.AdminSpecialBindSavePO;
import com.ksd.modules.special.service.IAdminSpecialBindService;
import com.ksd.modules.special.vo.AdminSpecialBindVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AdminSpecialBindController extends BaseController {
    
    @Autowired
    private IAdminSpecialBindService adminSpecialBindService;

    /**
     * 【专题绑定】- 列表
     * @return
     */
    @PostMapping("/special/bind/list")
    public R<List<AdminSpecialBindVo>> findAdminSpecialBinds(@RequestParam("specialId")Long specialId){
        return R.data(adminSpecialBindService.findAdminSpecialBinds(specialId));
    }

    /**
     * 【专题绑定】 - 保存和更新
     * @param adminSpecialBindSavePO
     * @return
     */
    @PostMapping("/special/bind/saveupdate")
    @ApiLog("【专题绑定】 - 保存和更新")
    @RepeatSubmit
    public R<Boolean> saveUpdateAdminSpecialBinds(@Validated @RequestBody AdminSpecialBindSavePO adminSpecialBindSavePO){
        return R.data(adminSpecialBindService.saveUpdateAdminSpecialBind(adminSpecialBindSavePO));
    }

    /**
     * 【专题绑定】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/special/bind/get/{id}")
    public R<AdminSpecialBindVo> getAdminSpecialBindsById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindService.getAdminSpecialBindById(id));
    }


    /**
     * 【专题绑定】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/special/bind/remove/{id}")
    @ApiLog("【专题绑定】- 根据ID恢复删除")
    public R<Boolean> removeAdminSpecialById(@PathVariable("id")Long id){
        return R.data(adminSpecialBindService.removeAdminSpecialBindById(id));
    }

    /**
     * 【专题绑定】- 修改状态
     *
     * @return
     */
    @PostMapping("/special/bind/status/{id}/{field}")
    @ApiLog("【专题绑定】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminSpecialBindService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminSpecialBindService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【专题绑定】 - 复制数据
     * @param opid
     * @return
     */
    @PostMapping("/special/bind/copy/{opid}")
    @ApiLog("【专题绑定】 -复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminSpecialBindService.copyData(opid));
    }
}
